﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Presenters.Cistern.Search;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Cistern
{
    public class PresenterSearchCistern
    {
        ISearchCisternView view;
        public PresenterSearchCistern(ISearchCisternView view)
        {
            this.view = view;
        }

        public void SearchCistern()
        {
            try
            {
                Model.Cistern c = new Model.Cistern() { Person = new Model.Person() { Names = view.PersonNamesRelative, LastNames = view.PersonLastNamesRelative }, LicencePlate = view.PlateCistern };
                view.CisternFinded = ManagerCistern.SearchCisternByParameter(c, view.StateCistern);
            }
            catch (Exception ex)
            {
                view.CisternFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }

        public void DisableCistern()
        {
            if (view.NotifyConfirmationMessage("Desea realmente inhabilitar la cisterna?"))
            {
                ManagerCistern.DisableCistern(CisternForDisable);
                view.NotifySystemMessage("La cisterna fue deshabilitado Exitosamente");
                CisternForDisable = null;
                HideDisableCistern();
                ClenSearch();
            }
        }

        private void ClenSearch()
        {
            view.CisternFinded = null;
            view.PersonLastNamesRelative = string.Empty;
            view.PersonNamesRelative = string.Empty;
            view.PlateCistern = string.Empty;
        }

        public void HideDisableCistern()
        {
            view.HideDisableCistern();
        }
        public Model.Cistern CisternForDisable { get; set; }

        public void ShowDisableCistern()
        {
            if (view.NotifyConfirmationMessage("Desea realmente inhabilitar la cisterna?"))
            {
                view.OpenDisableKardexPopUp(ManagerCistern.GetCisternByPlate(view.CisternSelected));
                CisternForDisable = view.CisternSelected;
                DisableCistern();
            }
        }

    }
}
